<template>
    <div class="dataManagement-queue-Lu">
        <div class="waiting-content-v">
            <commpVxeTable
            :key="refreshTable"
            :isCanWrap="true"
            :config="dataTableConfig"
            :columns="columnsVxe"
            :formItem="formItem"
            ref="acceptanceRegistrationRef"

            >
                <template v-slot:externalOperations="{data}">
                    <vxe-form-item>
                        <template>
                            <a-button class="blue-btn" type="primary" @click="addClick(0)">新增</a-button>
                        </template>
                    </vxe-form-item>
                </template>
                <template v-slot:ffbzt_name="{row}">
                    <span style="color: #5470c6;" v-if="row.ffbzt == '草稿'">草稿</span>
                    <span style="color: #91cc75;" v-if="row.ffbzt == '已发布'">已发布</span>
                    <span style="color: #ee6666;" v-if="row.ffbzt == '已下架'">已下架</span>
                </template>
                <template v-slot:operation_btn="{row}">
                    <a-form layout="inline" class="search-form" >
                        <a-form-item >
                            <a-button class="blue-btn" type="primary" @click="editClick(row,0,true)">查看</a-button>
                        </a-form-item>
                        <a-form-item >
                            <a-button class="blue-btn" type="primary" @click="editClick(row,0,false)">编辑</a-button>
                        </a-form-item>
                        <a-form-item v-if="row.ffbzt !== '已发布'">
                            <a-button class="blue-btn" type="primary" @click="releaseClick(row,0)">发布</a-button>
                        </a-form-item>
                        <a-form-item v-if="row.ffbzt == '已发布'">
                            <a-button class="red-btn" type="primary" @click="offShelfClick(row,0)">下架</a-button>
                        </a-form-item>
                    </a-form>
                </template>
            </commpVxeTable>
            <addEdit ref="addEditRef0" @addItem="addItem" @editItem="editItem" @tableSearchEvent="tableSearchEvent" />
        </div>
    </div>
</template>
<script>
import assessCheckApi from './service/api'
import commpVxeTable from '@/components/commp-vxe-table/commp-vxe-table.vue'
import blobType from '@/common/blobType'
import moment from 'moment'
import {
    partyXxzldeleteXxzl,
    partyXxzlsaveLjxczl,
    saveLlxxzl,
    releaseXXzl,
    xjXxzl,
} from './service/index'
import addEdit from './addEdit'
export default {
    components:{
        commpVxeTable,
        addEdit,
    },
    props:{
        fzllx:{
            type: String,
            default: '',
            required: false
        }
    },
    data(){
        return{
            formItem:[{
                label: '标题',
                model: 'fb',
            },{
                label: '摘要',
                model: 'fzy',
            },{
                label: '发布状态',
                model: 'ffbzt',
            }],
            columnsVxe:[
            {
                type: 'checkbox',
                width: 60 ,
                fixed: 'left'
            },{
                title: '标题', //列头显示文字
                field: 'fbt',
                // align:'left',
                // slots: {
                //     default: 'fsxmc_name',
                // },
            },{
                title: '摘要', //列头显示文字
                field: 'fzy',
                align:'left',
            },{
                title: '发布人',
                field: 'ffbr',
            },{
                title: '发布时间',
                field: 'ffbsj',
            },{
                title: '资源来源',
                field: 'fzyly',
            },{
                title: '阅读次数',
                field: 'fydcs',
                width:90,
            },{
                title: '下载次数',
                field: 'fxzcs',
                width:90,
            },{
                title: '发布状态',
                field: 'ffbzt',
                slots: {
                    // 使用插槽模板渲染
                    default: 'ffbzt_name',
                },
            },{
                title: '操作',
                field: 'id',
                slots: {
                    // 使用插槽模板渲染
                    default: 'operation_btn',
                },
                fixed: 'right',
                width:300
            }
            ],
            dataTableConfig:{
                api: assessCheckApi.queryLlxxzlGlPageList,
                rowId: 'id',
                paramet:{
                    fzllx:this.fzllx
                }
            },
            addEditParameter:{},
            methodList:[{
                name:'',
                editName:partyXxzlsaveLjxczl,
                deleteName:partyXxzldeleteXxzl,
                addName:partyXxzlsaveLjxczl,
                release:releaseXXzl,
                offShelf:xjXxzl
            }],
            refreshTable:null,

        }
    },
    watch:{

    },
    mounted(){

    },
    methods:{
        tableSearchEvent(){
            this.$refs.acceptanceRegistrationRef.searchEvent()
        },
        addClick(index){
            let refName = 'addEditRef'+index
            this.$refs[refName].getData({index:index,fzllx:this.fzllx})
            this.$refs[refName].visible = true
        },
        editClick(val,index,view){
            let refName = 'addEditRef'+index
            this.$refs[refName].getData({...val,fzllx:this.fzllx,index:index,view:view?true:false})
            this.$refs[refName].visible = true
        },
        addItem(val,vis,isTip){
            //console.log('新增',val)
            let refName = 'addEditRef'+val.index
            this.methodList[val.index].addName(val).then(res=>{
                if(res.code == 200){
                    this.refreshTable = Date.now()
                    if(!isTip){
                        this.$message.success(res.message)
                    }

                    this.$refs[refName].getData({...val,id:res.result.id})
                    this.$refs[refName].visible = vis
                    //console.log(res)
                }else{
                    this.$message.warning(res.message)
                }
            })
        },
        editItem(val,vis){
            //console.log('编辑',val)
            let refName = 'addEditRef'+val.index
            this.methodList[val.index].editName(val).then(res=>{
                if(res.code == 200){
                    this.refreshTable = Date.now()
                    this.$message.success(res.message)
                    this.$refs[refName].visible = vis
                }else{
                    this.$message.warning(res.message)
                }
            })
        },
        // 发布
        releaseClick(val,index){
            var that = this
            this.$confirm({
                title:'您确认要发布'+val.fbt+'吗？',
                onOk() {
                    that.methodList[index].release({id:val.id}).then(res=>{
                        if(res.code == 200){
                            that.$message.success(res.message)
                            that.refreshTable = Date.now()
                        }else{
                            that.$message.warning(res.message)
                        }
                    })
                },
            });
        },
        // 下架
        offShelfClick(val,index){
            var that = this
            this.$confirm({
                title:'您确认要下架'+val.fbt+'吗？',
                onOk() {
                    that.methodList[index].offShelf({id:val.id}).then(res=>{
                        if(res.code == 200){
                            that.$message.success(res.message)
                            that.refreshTable = Date.now()
                        }else{
                            that.$message.warning(res.message)
                        }
                    })
                },
            });
        },
    }
}
</script>
<style lang="less">
.dataManagement-queue-Lu{
    background: #fff;
    .waiting-content-v{
        height: calc(100vh - 191px -48px);
    }
}
</style>
